package com.helloniu.wb.tools {

import com.helloniu.wb.containers.ShapeTypeDef;
import com.helloniu.data.wb.LineStyle;
import com.helloniu.data.wb.WBColor;
import flash.geom.Point;

public class PencileTool extends DrawingTool {
    public function PencileTool() {
        super();
        
        this.setWBStyle(new LineStyle(), false);
        this.setShapeType(ShapeTypeDef.PENCILE);
    }

    override public function setEndPoint(endP:Point, appendEnd:Boolean = true):void {
        shapeRawData.push(endP);
    }

    override protected function resetMoveVars():void{
        var arr:Array = getShapePoints();

        for(var i:int = 0; i < arr.length; i++) {
            var sp:Point = arr[i] as Point;
            var spX:Number = sp.x + moveDistanceX;
            var spY:Number = sp.y + moveDistanceY;

            arr[i] = new Point(spX, spY);
        }

        setShapePoints(arr);
    }

    override protected function repaint():void {
        updateDisplayList(0, 0);
    }

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
		drawPencile();
    }

    private function drawPencile():void {        
        if(getCurrWBStyle() is LineStyle) {
			setWBStyle(getCurrWBStyle());
		}

        var lineColor:WBColor = (getWBStyle() as LineStyle).lineColor;
		var lineWidth:uint = (getWBStyle() as LineStyle).lineWidth;
				
        graphics.clear();
        graphics.lineStyle(lineWidth, lineColor.color, lineColor.alpha);

        var shapeDots:Array = getShapePoints();
        var len:Number  = shapeDots.length;

        for(var i:int = 0; i < len - 1; i++) {
            var sp:Point = shapeDots[i];
            var ep:Point = shapeDots[i + 1];

            graphics.moveTo(sp.x, sp.y);
            graphics.lineTo(ep.x, ep.y);
        }
    }    
}
}